<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="项目标识" prop="projectId">
        <el-select filterable
          v-model="queryParams.projectId"
          placeholder="请选择项目标识"
          style="width: 240px"
        >
          <el-option
            v-for="dict in proJectList"
            :key="dict.id"
            :label="dict.name"
            :value="dict.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="设备SN" prop="deviceSn">
        <el-input
          v-model="queryParams.deviceSn"
          placeholder="请输入设备SN"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="技术上报原因" prop="rea">
        <el-select
          v-model="queryParams.rea"
          placeholder="请选择技术上报原因"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in dict.type.device_reason_report"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间" prop="dateRange">
        <el-date-picker
          v-model="queryParams.dateRange"
          style="width: 333px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="datetimerange"
          range-separator="-" :clearable="false"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00','23:59:59']"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list">
      <el-table-column label="车位编号" align="center" prop="parkspaceName" fixed="left" width="150px"/>
      <el-table-column label="所属车场" align="center" prop="parklotName" width="150px"/>
      <el-table-column label="设备SN" align="center" prop="deviceSn" width="150px" />
      <el-table-column label="计数" align="center" prop="cnts" width="150px" />
      <el-table-column label="上报原因" align="center" prop="rea" width="150px">
        <template slot-scope="{row}">
          <dict-tag :options="dict.type.device_reason_report" :value="row.rea"/>
        </template>
      </el-table-column>
      <el-table-column label="版本" align="center" prop="version"  width="150px"/>
      <el-table-column label="SIM卡的IMSI号" align="center" prop="imsi"  width="150px"/>
      <el-table-column label="设备时间" align="center" prop="deviceTime"  width="150px"/>
      <el-table-column label="电池电压" align="center" prop="voltage"  width="150px"/>
      <el-table-column label="信号强度" align="center" prop="signal"  width="150px"/>
      <el-table-column label="入网时间" align="center" prop="inTime"  width="150px"/>
      <el-table-column label="响应时间" align="center" prop="outTime"  width="150px"/>
      <el-table-column label="有车概率" align="center" prop="probability"  width="150px"/>
      <el-table-column label="进入PSM时间" align="center" prop="psmTime"  width="150px"/>
      <el-table-column label="红外" align="center" prop="hw" width="150px" />
      <el-table-column label="磁场X" align="center" prop="mx" width="150px" />
      <el-table-column label="磁场Y" align="center" prop="my"  width="150px"/>
      <el-table-column label="磁场Z" align="center" prop="mz" width="150px" />
      <el-table-column label="磁场x初始值" align="center" prop="mx0" width="150px" />
      <el-table-column label="磁场y初始值" align="center" prop="my0"  width="150px"/>
      <el-table-column label="磁场z初始值" align="center" prop="mz0" width="150px" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="150px"  />
      <el-table-column label="地磁稳定时间" align="center" prop="magStabilityTime" width="150px" fixed="right" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="{row}">
          <el-button
            size="mini"
            type="text" v-hasPermi="['protocol:tianBo:setInitialValue']"
            @click="handleChuShi(row)"
          >设置初值</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { getList,setInitialValue,} from "@/api/parking/tianboReportRecord";
import { listAllFaParkProject,} from "@/api/config/projectPushManage";
import { getDay,getEndStartTime,YyMmDdToTimes,} from "@/utils/time";
export default {
  name: "TianboReportRecord",
  dicts: ['berth_park_status','device_reason_report','device_abnormal_state'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 字典表格数据
      list: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectId:null,
        parklotName:null,
        parkspaceName:null,
        deviceSn:null,
        car:null,
        rea:null,
        unusualStatus:null,
        dateRange:[],
      },
      proJectList:[],//项目列表数据
    };
  },
  created() {
    this.listAllFaParkProject()
  },
  methods: {
    handleChuShi(row){//设置初始值
      const deviceSn = row.deviceSn 
      this.$modal.confirm('是否确认还原设置该选项初始值？').then(function() {
        return setInitialValue({deviceSn,x0:row.mx,y0:row.my,z0:row.mz,});
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("c操作成功");
      }).catch(() => {});
    },
    getleidas(series,xAxis){
      this.chart = this.$echarts.init(this.$refs.leida,)
      this.chart.setOption({
        xAxis: {
          type: 'category',
          data: xAxis
        },
        yAxis: {
          type: 'value'
        },
        series: [
          { data: series, type: 'line' },
        ]
      })
    },
    async listAllFaParkProject(){//获取项目
      let res = await listAllFaParkProject()
      let data = res.data || []
      this.proJectList = data
      this.getList();
    },
    getInitTime(){//初始化时间
      let end = getDay(0)
      let start = getDay(0)
      let time = getEndStartTime([start,end])
      let queryParams = {...this.queryParams}
      queryParams.dateRange = [time.startTime3,time.endTime4]
      this.queryParams = {...queryParams}
      return queryParams.dateRange
    },
    /** 查询列表 */
    getList() {
      if(!this.queryParams.projectId) {
        let queryParamss = {...this.queryParams}
        if(this.proJectList.length) queryParamss.projectId = this.proJectList[0].id
        this.queryParams = {...queryParamss}
      }
      let queryParams = {...this.queryParams}
      let dateRange = queryParams.dateRange || []
      if(!dateRange.length) dateRange = this.getInitTime()
      if(dateRange.length) {
        queryParams.startTime = dateRange[0]
        queryParams.endTime = dateRange[1]
      }
      let day30 = getDay(30,queryParams.startTime,true)
      let endStr = YyMmDdToTimes(queryParams.endTime)
      let endStr30 = YyMmDdToTimes(day30)
      if(endStr > endStr30) return this.$modal.msgError("请选择30天内的数据");
      this.loading = true;
      delete queryParams.dateRange
      getList(queryParams).then(response => {
        this.list = response.rows || [];
        this.total = response.total || 0;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>

<style lang="scss" scoped>
.leida{
  height: 400px;width: 100%;
}
</style>